package com.haozhen.demo

/**
  * @author haozhen
  * @email haozh@ync1.com
  * @date 2021/2/8  0:38
  */
object WordCountScalaBatch {

  def main(args: Array[String]): Unit = {
    import org.apache.flink.api.scala._
    val inputPath = "data/input/hello.txt"
    val output = "data/output2"

    val environment: ExecutionEnvironment = ExecutionEnvironment.createCollectionsEnvironment

    val ds1: DataSet[String] = environment.readTextFile(inputPath)
    val result: AggregateDataSet[(String, Int)] = ds1.flatMap(_.split(" ")).map((_,1)).groupBy(0).sum(1)

    result.writeAsCsv(output)

    environment.execute()
  }
}
